<?php
namespace app\common\model;

use think\Model;

class GoodsCate extends Model
{
    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getList() {
        $list = $this->order('pid asc,sort desc')->select();
        $clist = [];
        foreach ($list as $v) {
            $v = $v->toArray();
            if ($v['pid'] > 0) {
                $v['ptitle'] = $clist[$v['pid']]['title'];
                $clist[$v['pid']]['list'][] = $v;
            } else {
                $clist[$v['id']] = $v;
            }
        }
        return $clist;
    }
}